#include "router.hpp"
#include <iostream>
#include <tuple>
#include <vector>

void testRoute() {
  std::vector<std::tuple<std::string, std::string, bool>> testCases = {
      {"aaa", "aaa", true},
      {"aaa.bbb", "aaa.bbb", true},
      {"aaa.bbb", "aaa.bbb.ccc", false},
      {"aaa.bbb", "aaa.ccc", false},
      {"aaa.#.bbb", "aaa.bbb.ccc", false},
      {"aaa.bbb.#", "aaa.ccc.bbb", false},
      {"#.bbb.ccc", "aaa.bbb.ccc.ddd", false},
      {"aaa.bbb.ccc", "aaa.bbb.ccc", true},
      {"aaa.*", "aaa.bbb", true},
      {"aaa.*.bbb", "aaa.bbb.ccc", false},
      {"*.aaa.bbb", "aaa.bbb", false},
      {"#", "aaa.bbb.ccc", true},
      {"aaa.#", "aaa.bbb", true},
      {"aaa.#", "aaa.bbb.ccc", true},
      {"aaa.#.ccc", "aaa.ccc", true},
      {"aaa.#.ccc", "aaa.bbb.ccc", true},
      {"aaa.#.ccc", "aaa.aaa.bbb.ccc", true},
      {"#.ccc", "ccc", true},
      {"#.ccc", "aaa.bbb.ccc", true},
      {"aaa.#.ccc.ccc", "aaa.bbb.ccc.ccc.ccc", true},
      {"aaa.#.bbb.*.bbb", "aaa.ddd.ccc.bbb.eee.bbb", true},
      {"*", "aaa", true},
      {"*", "aaa.bbb", false},
      {"#.aaa", "aaa", true},
      {"#.aaa", "bbb.aaa", true},
      {"aaa.*.*", "aaa.bbb.ccc", true},
      {"aaa.*.*", "aaa.bbb", false},
      {"aaa.*.#", "aaa.bbb.ccc.ddd", true},
      {"aaa.*.#", "aaa.bbb", true},
      {"aaa.*.*.#", "aaa.bbb.ccc.ddd", true},
      {"aaa.*.*.#", "aaa.bbb", false}};

  for (const auto &[BindingKey, RouteKey, expected] : testCases) {
    if (BindingKey == "#.aaa") {
      int tmp = 200;
    }
    bool result = MY_MQ::Router::matching(BindingKey, RouteKey);
    if (result == expected) {
    } else {
      std::cout << "FAIL: " << BindingKey << " -> " << RouteKey << " (expected "
                << expected << ", got " << result << ")\n";
    }
  }
}
void TestIsLegalBindingKey() {
  std::vector<std::pair<std::string, bool>> test_cases = {
      {"key1", true},        {"key_123", true},    {"1_2_3", true},
      {"a.b", true},         {"abc_123", true},    {"key..value", false},
      {"a.b.c", true},      {"key.1.2", true},   {"key#value",false},
      {"key1*value", false},  {"a.#b", false},      {"a.*b", false},
      {"key@value", false},  {"key!value", false}, {"key^value", false},
      {"key#*value", false}, {"*#value", false},   {"key##value", false}};

  for (const auto &[input, expected] : test_cases) {
    bool result = MY_MQ::Router::IsLegalBindingKey(input);
    if (result == expected) {
      // std::cout << "Test passed for: " << input << std::endl;
    } else {
      result = MY_MQ::Router::IsLegalBindingKey(input);

      std::cout << "Test failed for: " << input << std::endl;
    }
  }
}

int main() {
  TestIsLegalBindingKey();
  return 0;
}
